package com.foodorder.repository;

import com.foodorder.entity.DeliveryStaff;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * 配送员数据访问接口
 */
@Repository
public interface DeliveryStaffRepository extends JpaRepository<DeliveryStaff, Long> {
    
    /**
     * 根据手机号查找配送员
     */
    Optional<DeliveryStaff> findByPhone(String phone);
    
    /**
     * 根据商店ID和工作状态查找配送员
     */
    List<DeliveryStaff> findByStoreIdAndWorkingStatus(Long storeId, DeliveryStaff.WorkingStatus workingStatus);
    
    /**
     * 查找可用的配送员
     */
    @Query("SELECT d FROM DeliveryStaff d WHERE d.workingStatus = com.foodorder.entity.DeliveryStaff$WorkingStatus.ONLINE AND d.status = com.foodorder.entity.DeliveryStaff$DeliveryStaffStatus.ACTIVE")
    List<DeliveryStaff> findAvailableStaff();
    
    /**
     * 根据工作状态统计配送员数量
     */
    long countByWorkingStatus(DeliveryStaff.WorkingStatus workingStatus);
}